# Build stage
FROM node:18-alpine AS builder

WORKDIR /code

# Install pnpm and set up environment
RUN corepack enable && \
  corepack prepare pnpm@latest --activate && \
  pnpm config set registry https://registry.npmmirror.com

# 复制源代码
COPY . .
# 安装依赖
RUN pnpm install



# 构建应用
RUN pnpm build

# 生产阶段
FROM nginx:alpine

# 创建必要的目录
RUN mkdir -p /etc/nginx/certs

# 复制构建后的文件
COPY --from=builder /code/dist /usr/share/nginx/html

# 复制 nginx 配置
COPY --from=builder /code/dist/nginx.conf /etc/nginx/nginx.conf
# 复制 SSL 证书（从主机的 ssl 目录复制到容器的 /etc/nginx/certs/ 目录）
COPY --from=builder /code/dist/ssls/ /etc/nginx/certs/

# 暴露 80 和 443 端口
EXPOSE 80
EXPOSE 443

# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]